public class ThreadDemo1 {
    public static void main(String[] args) {

        Thread thread=new Thread(()->{
            int n=0;
            while(!Thread.currentThread().isInterrupted()){  //获取线程引用的对象，通过Thread.currentThread();
                System.out.println("hello"+n);
                n++;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        thread.start();
        for (int i = 0; i < 100; i++) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        thread.interrupt();  //线程的中断，但中断不中断还是要线程任务想中断不，它就是通知一下线程中断，并不会真得使得线程中断

    }
}
